package com.ruoyi.ams.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ruoyi.ams.domain.vo.DeptAssetNumberVo;
import com.ruoyi.ams.domain.vo.IotAssetInfo;
import com.ruoyi.ams.mapper.AmsAssetInfoMapper;
import com.ruoyi.ams.service.IAmsAssetInfoService;
import com.ruoyi.common.core.domain.AsmsAssetFullInfo;
import com.ruoyi.common.core.domain.model.AmsAssetInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

/**
 * 资产基础信息Service业务层处理
 * 
 * @author yfkj
 * @date 2021-10-15
 */
@Service
public class AmsAssetInfoServiceImpl extends ServiceImpl<AmsAssetInfoMapper, AmsAssetInfo>  implements IAmsAssetInfoService
{
    @Autowired
    private AmsAssetInfoMapper amsAssetInfoMapper;

    /**
     * 查询资产基础信息
     * 
     * @param assetId 资产基础信息主键
     * @return 资产基础信息
     */
    @Override
    public Object selectAmsAssetInfoByAssetId(Long assetId)
    {
        return amsAssetInfoMapper.selectAmsAssetInfoByAssetId(assetId);
    }

    /**
     * 查询资产基础信息列表
     * 
     * @param amsAssetInfo 资产基础信息
     * @return 资产基础信息
     */
    @Override
    public List<AmsAssetInfo> selectAmsAssetInfoList(AmsAssetInfo amsAssetInfo)
    {
        return amsAssetInfoMapper.selectAmsAssetInfoList(amsAssetInfo);
    }

    /**
     * 新增资产基础信息
     * 
     * @param amsAssetInfo 资产基础信息
     * @return 结果
     */
    @Override
    public int insertAmsAssetInfo(AmsAssetInfo amsAssetInfo)
    {
        amsAssetInfo.setCreateTime(System.currentTimeMillis());
        return amsAssetInfoMapper.insertAmsAssetInfo(amsAssetInfo);
    }

    /**
     * 修改资产基础信息
     * 
     * @param amsAssetInfo 资产基础信息
     * @return 结果
     */
    @Override
    public int updateAmsAssetInfo(AmsAssetInfo amsAssetInfo)
    {
        amsAssetInfo.setUpdateTime(System.currentTimeMillis());
        return amsAssetInfoMapper.updateAmsAssetInfo(amsAssetInfo);
    }

    /**
     * 批量删除资产基础信息
     * 
     * @param assetIds 需要删除的资产基础信息主键
     * @return 结果
     */
    @Override
    public int deleteAmsAssetInfoByAssetIds(Long[] assetIds)
    {
        return amsAssetInfoMapper.deleteAmsAssetInfoByAssetIds(assetIds);
    }

    /**
     * 删除资产基础信息信息
     * 
     * @param assetId 资产基础信息主键
     * @return 结果
     */
    @Override
    public int deleteAmsAssetInfoByAssetId(Long assetId)
    {
        return amsAssetInfoMapper.deleteAmsAssetInfoByAssetId(assetId);
    }

    @Override
    public List<AmsAssetInfo> getAmsAssetInfoByDeptIds(List<Long> deptIds,Long startTime,Long endTime,Long assetTemplateId) {
        return amsAssetInfoMapper.getAmsAssetInfoByDeptIds(deptIds,startTime,endTime,assetTemplateId);
    }
    @Override
    public List<AsmsAssetFullInfo> getAllAssetInfoByDeptIds(List<Long> deptIds, Long startTime, Long endTime, Long assetTemplateId){
        return amsAssetInfoMapper.getAllAssetInfoByDeptIds(deptIds, startTime, endTime, assetTemplateId);
    }

    @Override
    public List<AsmsAssetFullInfo> getAllAssetInfo(List<Long> deptIds){
        return amsAssetInfoMapper.getAllAssetInfo(deptIds);

    }

    @Override
    public List<AmsAssetInfo> getAllLock(List<Long> deptIds) {

        return amsAssetInfoMapper.getAllLock(deptIds);
    }

    @Override
    public List<DeptAssetNumberVo> getDeptAssetNumber(List<Long> deptIds) {

        List<HashMap> deptAssetNumber = amsAssetInfoMapper.getDeptAssetNumber(deptIds);

        List<DeptAssetNumberVo> numberVos = new LinkedList<>();

        for(HashMap<String,Object> number: deptAssetNumber){
            numberVos.add(new DeptAssetNumberVo((Long)number.get("deptId"),(Long)number.get("assetNumber")));
        }

        return numberVos;
    }

    @Override
    public List<IotAssetInfo> getIotAssetBasicList(Long useDeptId, String addressName) {
        return amsAssetInfoMapper.getIotAssetBasicList(useDeptId,addressName);
    }
}
